﻿using Super_Management_Mayhem.Content.Animations;
using Super_Management_Mayhem.Content.Spritesheet;
using Transformable_Engine_v2.Engine.Animation.FrameAnimation;
using Transformable_Engine_v2.Engine.GameObjects.Containers;
using Transformable_Engine_v2.Engine.Global;
using Transformable_Engine_v2.Engine.Transformable_Math.Geometry;

namespace Super_Management_Mayhem.Screens.Playing.Tiles
{
    public class Switch : Container
    {
        public bool State { get; set; }

        private ImageContainer _lever;

        public override void LoadContent()
        {
            AddChildren(new ImageContainer
            {
                Sprite = ItemSheet.GetSprite(ItemSheet.Tile.ItemTile),
            });

            _lever = new ImageContainer
                {
                    PositionGridBound = new TE_Vector2(0.5f, 0.65f),
                    Sprite = ItemSheet.GetSprite(State ? ItemSheet.Switch.On : ItemSheet.Switch.Off),
                    Origin = TE_Rectangle.Alignment.BottomMiddle
                };

            AddChildren(_lever);
            base.LoadContent();
        }

        public void Toggle()
        {
            switch (State)
            {
                case true:
                    _lever.AddAnimations(new FrameAnimation(new ToggleOff()));
                    break;
                case false:
                    _lever.AddAnimations(new FrameAnimation(new ToggleOn()));
                    break;
            }

            State = !State;
            Log.LogInfo("Switch toggled " + (State ? "on" : "off"));
        }
    }
}